package com.common.DAO;

import java.util.List;

import org.apache.log4j.Logger;

import com.common.entity.Comment;

public class CommentDAO extends BaseDAO implements ICommentDAO {
	
	Logger logger = Logger.getLogger(CommentDAO.class);

	@SuppressWarnings("unchecked")
	@Override
	public List<Comment> list() {
		try{
			List<Comment> coList = super.list("from Comment");
			return coList;
		}catch (Exception e) {
			logger.error("erreur requete",e);
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Comment> listPathComment(int path_id) {
		try{
			List<Comment> coList = super.list("from Comment where fk_trajet="+path_id);
			return coList;
		}catch (Exception e) {
			logger.error("erreur requete",e);
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Comment> listApplicationComment() {
		try{
			List<Comment> coList = super.list("from Comment where fk_trajet=0 AND fk_covoit_recepteur=0");
			return coList;
		}catch (Exception e) {
			logger.error("erreur requete",e);
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Comment> listCovoitureurComment(int covoit_id) {
		try{
			List<Comment> coList = super.list("from Comment where fk_covoit_recepteur="+covoit_id);
			return coList;
		}catch (Exception e) {
			logger.error("erreur requete",e);
		}
		return null;
	}

	@Override
	public void addComment(Comment co) {
		logger.info("addComment()");
		try{
			super.save(co);
		}catch (Exception e) {
			logger.error("erreur in DAO while adding a comment");
		}
		logger.info("addComment() done");
	}
	
	
	
}
